package org.vartist.atld.menu.task.util.base64;

import org.vartist.atld.menu.activity.util.base64.Base64Activity;
import org.vartist.atld.util.image.ImageUtil;

import android.graphics.Bitmap;
import android.os.AsyncTask;

public class LoadImageTask extends AsyncTask<String, Integer, Long> {

	private Base64Activity mActivity = null;
	private String mImageURL = null;
	private Bitmap mReturnBitmapImage = null;
	
	public LoadImageTask(Base64Activity activity, String imageURL) {
		mActivity = activity;
		mImageURL = imageURL;
	}
	
	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		mActivity.setProgressVisibility(true);
	}
	
	@Override
	protected Long doInBackground(String... arg0) {
		if (!isCancelled()) {
			mReturnBitmapImage = ImageUtil.getBitmapFromURL(mImageURL);	
		}
		
		return null;
	}

	@Override
	protected void onPostExecute(Long result) {
		super.onPostExecute(result);
		
		if (!isCancelled()) {
			mActivity.setResultForLoadImage(mReturnBitmapImage);	
		}
		
		mActivity.setProgressVisibility(false);
	}
	
	@Override
	protected void onCancelled() {
		super.onCancelled();
	}
}